package com.wuye.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.wuye.common.dao.hibernate.BaseDaoHibernate;
import com.wuye.common.util.string.StrUtil;
import com.wuye.common.vo.PageInfo;
import com.wuye.dao.OrgDao;
import com.wuye.entity.Organization;
import com.wuye.entity.PropertyCompany;

@Repository("orgDao")
public class OrgDaoImpl extends BaseDaoHibernate implements OrgDao
{

	public Organization getOrganization(int orgId) 
	{		
		return (Organization)super.getObject(Organization.class, orgId);
	}

	public void addOrganization(Organization organization) throws Exception
	{
		super.addObject(organization);
	}

	public void delOrganization(int orgId) throws Exception
	{
		super.removeObject(Organization.class, orgId);		
	}

	public void updateOrganization(Organization organization) throws Exception
	{
		super.updateObject(organization);
		
	}

	public <E> PageInfo jdbcFindPageInfo(String sql, Class<E> elementType,
			List<Object> params, int currentPage, int perPageNum) {
		// TODO Auto-generated method stub
		return null;
	}

	public Organization getOrgByOrgTypeAndName(PropertyCompany company,
			String orgType, String orgName) {
		if (company == null || StrUtil.isNullOrEmpty(orgType) ||StrUtil.isNullOrEmpty(orgName)){
			return null;
		}
		List<Organization> childOrgs = company.getOrganization().getAllChild();
		if (childOrgs != null && childOrgs.size() > 1){
			for (Organization each : childOrgs){
				if (orgType.equals(each.getOrgType()) && orgType.equals(each.getOrgName())){
					return each;
				}
			}
		}
		return null;
	}

}
